package org.example.classload;

import java.sql.DriverManager;

public class ClassLoadStudy {

    public static void main(String[] args) throws ClassNotFoundException {
        // 启动类加载器
        String str = "hello";
        System.out.println("String ClassLoad is"+ str.getClass().getClassLoader()); //String ClassLoad isnull

        // 扩展类加载器
        ClassLoader extClassLoader = ClassLoader.getSystemClassLoader().getParent();
        System.out.println(extClassLoader);//sun.misc.Launcher$ExtClassLoader@135fbaa4
        // 扩展类的父加载器
        System.out.println("ext parent is" + extClassLoader.getParent());//ext parent isnull

        // 应用程序加载器
        System.out.println("app classload is  "+ClassLoadStudy.class.getClassLoader());//app classload is  sun.misc.Launcher$AppClassLoader@18b4aac2

        System.out.println("app parent is" + ClassLoadStudy.class.getClassLoader().getParent());//app parent issun.misc.Launcher$ExtClassLoader@135fbaa4
        System.out.println("app parent parent is" + ClassLoadStudy.class.getClassLoader().getParent().getParent());//app parent parent isnull

        // 破坏双亲委派
        Class<?> aClass1 = Class.forName("java.sql.DriverManager");
        System.out.println(aClass1.getClassLoader());
        Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println(aClass.getClassLoader());
    }
}
